<%--
  Created by IntelliJ IDEA.
  User: 85435
  Date: 2025/7/26
  Time: 10:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改书籍信息</title>
</head>
<body>

<div>
    <label> 书籍名称: </label><input type="text" name="bookName">
    <label> 书籍编号: </label><input type="text" name="bookNo">
    <label> 数量: </label><input type="text" name="count">
</div>
<div>
    <button onclick="add()">提交</button>
</div>
</body>
</html>
<script>
    function add() {
        //获取当前页面上的输入框的值，
        let bookNameInput = document.querySelector("input[name=bookName]");
        let bookName = bookNameInput.value
        let countInput = document.querySelector("input[name='count']");
        let count = countInput.value
        let bookNoInput = document.querySelector("input[name='bookNo']");
        let bookNo = bookNoInput.value

        //传递到后台，进行修改

        let xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                let respObj = JSON.parse(xhr.responseText);
                if (respObj.code == 200) {
                    alert("修改成功");
                }else{
                    alert(respObj.msg)
                }
            }
        }
        //如果是post请求，需要设置请求头

        xhr.open("post", "/book/add")
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send("bookName=" + bookName + "&count=" + count+"&bookNo="+bookNo);

    }


</script>
